package com.linsir.auth.auto;

import com.linsir.auth.auto.service.IAuthService;
import com.linsir.core.auto.annotation.AutoContextInitializer;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.ServiceLoader;

/**
 * @ClassName : AuthApplicationContextInitializer
 * @Description :
 * @Author : Linsir
 * @Date: 2023-12-26 09:11
 */


@Slf4j
@AutoContextInitializer
public class AuthApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {



    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        log.info("---{}-----{}------{}--------",applicationContext.getApplicationName(),
                applicationContext.getEnvironment(),applicationContext.isActive());

        ServiceLoader<IAuthService> loaders = ServiceLoader.load(IAuthService.class);
        PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        loaders.forEach(IAuthService::say);
    }
}
